#!/bin/sh

usage="Usage: $0 templfile [{\\\"key\\\",\\\"val\\\"},...]"
if [ -z "$1" ]; then
  echo $usage
  exit 1
fi

ERL=erl
ERL_ARGS="-boot start_clean -noinput"
SCRIPT="templ:init(), io:format(templ:process_file(\"$1\""

shift 1
CTX=`echo $*`
if [ -n "$CTX" ]; then
  SCRIPT="$SCRIPT, $CTX"
fi

SCRIPT="$SCRIPT)++\"~n\")."

$ERL $ERL_ARGS -eval "$SCRIPT" -s init stop
